/*
 *  SoundElementFactoryTester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/11/13.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "SoundElementFactoryTester.h"

#include "../SoundController.h"
#include "CustomAssert.h"

namespace sc {

	void SoundElementFactoryTester::TestAll()
	{
		Test_Create_001();
		
		Test_Create_002();
	}

	void SoundElementFactoryTester::Test_Create_001()
	{
		double length = 1.5;
		double powerOfX = 1;
		const WaveFunction& function = WaveFunctionFactory::CreateXSinX( powerOfX, 2 * length );
		const WaveFunction& functionRev = WaveFunctionFactory::CreateXSinX( powerOfX, 2 * length, true );

		const WaveTable& soundTable = WaveTableFactory::Create( WaveTable::Type_Constant, 1, 1 );
		const WaveTable& dynamicsTable = WaveTableFactory::Create( function, 1 );
		const WaveTable& dynamicsTableRev = WaveTableFactory::Create( functionRev, 1 );

		const SoundElement32* element = SoundElementFactory32::Create( soundTable, dynamicsTable, length );
		const SoundElement32* elementRev = SoundElementFactory32::Create( soundTable, dynamicsTableRev, length );

		AssertEqual( & element->GetDynamicsTable(), & dynamicsTable );
		AssertEqual( & elementRev->GetDynamicsTable(), & dynamicsTableRev );

		AssertEqual( & element->GetSoundTable(), & soundTable );
		AssertEqual( & elementRev->GetSoundTable(), & soundTable );

		AssertEqual( element->GetDuration(), length );
		AssertEqual( elementRev->GetDuration(), length );
	}

	void SoundElementFactoryTester::Test_Create_002()
	{
	
		SoundElementFactory32::DisposeInstances();
		
		NoteInfo info;

		info.duration = 3.3333;
		info.dynamics = 0.625;

		info.frequency = 92.4986;
		const WaveTable& dynamicsTable1 = WaveTableFactory::Create( WaveTable::Type_Sine, 1.0 / ( 2.0 * info.duration ), info.dynamics );
		const WaveTable& soundTable1 = WaveTableFactory::Create( WaveTable::Type_Sine, info.frequency, 1.0 );
		const SoundElement32* element1 = SoundElementFactory32::Create( soundTable1, dynamicsTable1, info.duration );

		info.frequency = 138.591;
		const WaveTable& dynamicsTable2 = WaveTableFactory::Create( WaveTable::Type_Sine, 1.0 / ( 2.0 * info.duration ), info.dynamics );
		const WaveTable& soundTable2 = WaveTableFactory::Create( WaveTable::Type_Sine, info.frequency, 1.0 );
		const SoundElement32* element2 = SoundElementFactory32::Create( soundTable2, dynamicsTable2, info.duration );

		AssertTrue( element1 != element2 );
		AssertTrue( *element1 != *element2 );
	}

}
